﻿#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QSqlQuery>
#include <QDebug>
#include <QMessageBox>

#pragma execution_character_set("utf-8")

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    this->setWindowOpacity(1);
    connect(&timer,&QTimer::timeout,this,&MainWindow::timeoutHandle);

}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::on_pB_login_clicked()
{
    QString username = ui->lE_username->text();
    QString password = ui->lE_password->text();

    // 判断用户名与密码非空
    if(username=="" || password == "")
    {
        QMessageBox::information(this,"提示","用户名或密码不能为空");
    }
    emit signInReqSignal(username,password);
    timer.start(5000);
}

void MainWindow::on_pB_cancle_clicked()
{
    this->close();
}

void MainWindow::on_pB_register_clicked()
{

    registerDialog = new Register(this);
    registerDialog->show();

}

void MainWindow::timeoutHandle()
{
    timer.stop();
    QMessageBox::warning(this,
                         "Warning",
                         QString("网络问题！\n登录可能超时"),
                         QMessageBox::Ok);

}

void MainWindow::keyPressEvent(QKeyEvent *event)
{
    if(event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return)
    {
        on_pB_login_clicked();
    }
}

void MainWindow::signInSucHandle()
{
    timer.stop();
    hide();
}

void MainWindow::signInFaildHandle()
{
    timer.stop();
    QMessageBox::warning(this,
                         "Warning",
                         QString("账号或密码错误"),
                         QMessageBox::Ok);
}
